﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

namespace HA.ModFlow.Controls
{
    public class PCGridArrayLayer<T>
    {
        public PCGridArrayLayer(T[,] data)
        {
            //_datas = new List<double[]>();

            

            //for (int i = 0; i < data.GetLength(0); i++)
            //{
            //    double[] rowData=new double[data.GetLength(1)];
            //    for (int j = 0; j < data.GetLength(1); j++)
            //    {
                    
            //        rowData[j]=data[i,j];
            //    }

            //    List<double> _rowDataList = new List<double>();
            //    _rowDataList.AddRange(rowData);

            //    this._datas.Add(_rowDataList);

               

                
            //}

            this._data = data;
 
        }

        T[,] _data;

        public T[,] Data
        {
            get { return _data; }
            set { _data = value; }
        }


    

      

      


        public static DataView GetBindable2DArray<T>(T[,] array)
        {
            DataTable dataTable = new DataTable();
            for (int i = 0; i < array.GetLength(1); i++)
            {
                dataTable.Columns.Add(i.ToString(), typeof(Ref<T>));
            }
            for (int i = 0; i < array.GetLength(0); i++)
            {
                DataRow dataRow = dataTable.NewRow();
                dataTable.Rows.Add(dataRow);
            }
            DataView dataView = new DataView(dataTable);
            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    int a = i;
                    int b = j;
                    Ref<T> refT = new Ref<T>(() => array[a, b], z => { array[a, b] = z; });
                    dataView[i][j] = refT;
                }
            }
            return dataView;
        }


    }
}
